package de.fuberlin.dbs.wm.dao.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class DatabaseSource {
	private static Connection conn;
	private static Statement stmt;
	
	/*private static final String DB_SERVICE = "XE";
	private static final String HOST = "127.0.0.1";
	private static final String USER = "reim";
	private static final String PASSWD = "test";*/
	
	private static final String DB_SID = "agdb";
	private static final String HOST = "esel.imp.fu-berlin.de";
	private static final String USER = "dbs_12";
	private static final String PASSWD = "dbs_12";
	
	/**
	 * Connect to Database
	 * @throws SQLException
	 * @throws ClassNotFoundException
	 */
	public static void setUpConnection() throws SQLException, ClassNotFoundException {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		DriverManager.setLoginTimeout(5);
		conn = DriverManager.getConnection("jdbc:oracle:thin:@" + HOST + ":1521:" + DB_SID, USER, PASSWD);
		stmt = conn.createStatement();
	}
	
	/**
	 * Close Database Connection
	 * @throws SQLException
	 */
	public static void closeConnection() throws SQLException {
		conn.close();
	}

	protected static ResultSet query(String sql) throws SQLException {
		return stmt.executeQuery(sql);
	}
	
	protected static int update(String sql) throws SQLException {
		return stmt.executeUpdate(sql);
	}
	
	public static Statement getStatement() {
		return stmt;
	}
}
